package copyengine.ui.component.list.old.dataprovider
{
	import copyengine.ui.component.list.old.cellrender.ICECellRenderData;

	public class CESingleRowDataProvider implements ICEListDataProvider
	{
		private var dataProvider:Vector.<ICECellRenderData>;

		public function CESingleRowDataProvider()
		{
			dataProvider = new Vector.<ICECellRenderData>();
		}

		public function clear():void
		{
			dataProvider.splice(0, dataProvider.length);
		}

		public function setDataVector(_data:Vector.<ICECellRenderData>):void
		{
			dataProvider.splice(0, dataProvider.length);
			if (_data)
			{
				for (var i:int = 0; i < _data.length; i++)
				{
					dataProvider.push(_data[i]);
				}
			}
		}

		public function getData():Vector.<ICECellRenderData>
		{
			return dataProvider;
		}

		public function pushData(_data:ICECellRenderData):void
		{
			dataProvider.push(_data);
		}

		public function deleteData(_data:ICECellRenderData):void
		{
			for (var i:int = 0; i < dataProvider.length; i++)
			{
				if (_data == dataProvider[i])
				{
					dataProvider.splice(i, 1);
					break;
				}
			}
		}

		public function sort(_sortFunction:Function):void
		{
			dataProvider.sort(_sortFunction);
		}

		public function forEach(_forEachFunction:Function):void
		{
			dataProvider.forEach(_forEachFunction);
		}

		public function filter(_filterFunction:Function):Vector.<ICECellRenderData>
		{
			return dataProvider.filter(_filterFunction);
		}

		public function dispose():void
		{
			dataProvider = null;
		}

		public function getDataByIndex(_index:int):ICECellRenderData
		{
			if (_index < dataProvider.length && _index >= 0)
			{
				return dataProvider[_index];
			}
			return null;
		}

		public function getGroupIndexByData(_data:ICECellRenderData):int
		{
			for (var i:int = 0; i < dataProvider.length; i++)
			{
				if (dataProvider[i] == _data)
				{
					return i;
				}
			}
			return int.MIN_VALUE;
		}

		public function get totalDataCount():int
		{
			return dataProvider.length;
		}

	}
}
